<template>
	<view class="time-select">
		<block v-for="(item,index) in timeItems">
			<view @click="selectFn(index)" :class="index==selectIndex?'time-item-active':'time-item'">
				{{item}}
			</view>
		</block>
	</view>
</template>

<script>
	export default {
		name: "timeSelect",
		props: ['timeType'],
		data() {
			return {
				timeItems: ['日', '周', '月'],
				selectIndex: 0
			}
		},
		methods: {
			selectFn(index) {
				this.selectIndex = index
				this.$emit('selectFn', this.selectIndex)
			}
		},
		computed: {
			index: function() {
				this.selectIndex = this.timeType
				return this.timeType
			}
		}
	}
</script>

<style lang="scss">
	.time-select {
		border-radius: 15rpx;
		display: flex;
		justify-content: space-around;
		padding: 10rpx;
		background-color: #f5f5f5;

		.time-item {
			position: relative;
			flex: 1;
			text-align: center;
			margin-right: 10rpx;
			padding: 10rpx 0;
			border-radius: 15rpx;


			&::after {
				position: absolute;
				top: 8rpx;
				right: 0;
				content: '';
				width: 2rpx;
				height: 50rpx;
				background-color: #dedede;
			}

			&:last-child {
				margin-right: 0;

				&::after {
					display: none
				}
			}
		}

		.time-item-active {
			@extend .time-item;
			background-color: white;

			&::after {
				display: none
			}
		}
	}

	.time-select {
		color: black;
	}
</style>